home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 5829 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.8 KB  |  108 lines

  1. Path: news.primenet.com!not-for-mail
  2. From: gbe@primenet.com (Gary Edstrom)
  3. Newsgroups: comp.lang.c++
  4. Subject: Bug? MSVC++ 4.0, Windows 95, Virtual Destructors, & DLL's
  5. Date: 6 Feb 1996 17:28:02 -0700
  6. Organization: Sequoia Software
  7. Sender: root@primenet.com
  8. Message-ID: <3117efd3.956426@news.primenet.com>
  9. X-Posted-By: ip076.lax.primenet.com
  10. X-Newsreader: Forte Agent .99c/16.141
  11.  
  12. Here's a strange problem that I have been trying to figure out all day
  13. today.  I have a program that consists of 2 parts:
  14.  
  15.   1. A  DLL that contains a simple class with an empty constructor
  16.      and an empty virtual destructor.
  17.  
  18.   2. An EXE that contains exactly the same type of class, but with a
  19.      different name.
  20.  
  21. All I do in the main program is to create an instance of the object
  22. via new, followed by an immediate delete object.  I do this for both
  23. types of objects.  The object that is defined in the main test module
  24. functions as expected.  However, when the function defined in the DLL
  25. is deleted, I get an assertion error from the debug library showing
  26. some sort of corruption on the heap.
  27.  
  28. IMPORTANT:
  29. This example will only show the problem if compiled in the Debug mode.
  30.  
  31. Can anyone else duplicate this problem?  Does anyone have any idea
  32. what is going on?  Have I come across some sort of compiler bug?  The
  33. only clue that I seem to have discovered is that the first version
  34. (the one resident in the EXE file) executes an internal function
  35. called "scaler deleting destructor", while the second version (the one
  36. defined in the DLL file) executes an internal function called "vector
  37. deleting destructor".
  38.  
  39.  
  40. ********* CONTENTS OF DLL.H **********
  41.  
  42. #ifdef DLL_OP
  43. #define Dll_Decl __declspec( dllexport )
  44. #else
  45. #define Dll_Decl __declspec( dllimport )
  46. #endif
  47.  
  48. class Dll_Decl object1
  49.     {
  50.     public:
  51.         object1();
  52.         virtual ~object1();
  53.     };
  54.  
  55. ********* CONTENTS OF DLL.C *********
  56.  
  57. #include "windows.h"
  58. #define DLL_OP
  59. #include "ipc.h"
  60.  
  61. object1::object1()  { }
  62. object1::~object1() { }
  63.  
  64. ********* CONTENTS OF TEST.CPP *********
  65.  
  66. #define STRICT
  67. #include <windows.h>
  68.  
  69. #include "dll.h"
  70.  
  71. class object2
  72.     {
  73.     public:
  74.         object2();
  75.         virtual ~object2();
  76.     };
  77.  
  78. object2::object2()  { }
  79. object2::~object2() { }
  80.  
  81. int WINAPI WinMain(
  82.     HINSTANCE  hInstance,     // handle to current instance
  83.     HINSTANCE  hPrevInstance, // handle to previous instance
  84.     LPSTR      lpCmdLine,     // pointer to command line
  85.     int        nShowCmd       // show state of window
  86.     )
  87.     {
  88.  
  89.     {
  90.     object2 * o2 = new object2;
  91.     delete o2;    // This delete executes OK
  92.     }
  93.  
  94.     {
  95.     object1 * o1 = new object1;
  96.     delete o1;    // This delete produces an assertion error
  97.     }
  98.  
  99.     return 0;
  100.     }
  101.  
  102. ********* END OF SAMPLE CODE *********
  103. --
  104. Gary Edstrom <gbe@primenet.com> | Sequoia Software
  105. PO Box 9573                     | Programming & Technical Services
  106. Glendale CA 91226-0573          | PGP Key ID: 0x1A0D44BD
  107. PGP Fingerprint: 72 AA 4F 73 05 53 89 C6  8A EE F4 EE D1 C0 13 8D 
  108.